package com.shang.spring.beans.hello;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        //创建对象
        //HelloWorld helloWorld = new HelloWorld();
        //赋值
        //helloWorld.setName("zhangsan");

        //创建Spring的IOC容器对象
        //ApplicationContext代表IOC容器
        //ClassPathXmlApplicationContext：是ApplicationContext接口的实现类，该实现类从类路径下来加载配置文件
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //从IOC中获取Bean实例
        HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
//        HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
        helloWorld.hello();


        Car car = ctx.getBean(Car.class);
        System.out.println(car);

        Person person = (Person) ctx.getBean("person");
        System.out.println(person);
    }
}
